/*
 * @Author: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @Date: 2022-03-25
 * @LastEditors: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @LastEditTime: 2022-07-14 10:54:37
 * @Description: 
 * @Administrator: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @Copyright: 文件版本号
 */
// import { DictionaryType, requestDict } from "../common/dictionary/dictionary-type.js";
// import FeedBackApi from '../common/api/ctn/feedback.api.js';
import { getAuthZ, TEST_NUMBER, TEST_INFO_NUMBER, Collaboration_APP, Service_APP } from '../../../../public/js/config/config.js'
/**
 *@file意见反馈
 *@Date :2022-03-25 16:52:09
 *@create周润玉
*/
(function (window, document, $) {
    'use strict';
    let _vm;
    $('#application-date').text(`2019-${new Date().getFullYear()}`);
    $('body').attr('data-weui-theme', 'light'); // 强制光明模式

    $(function () {
        _vm = new Vue({
            el: "#main-category",
            methods: {
                truckLoadingTime: function (param) {
                    // 保存当前的滚动距离
                    scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                    // 设置 fixed 布局
                    document.body.style.position = 'fixed';
                    document.body.style.height = '100%';
                    document.body.style.width = '100%';
                }
            }
        });
        _initRequestDict();
    });

    /**
     *@file 数据接口查询初始化
     *@Date :2022-04-15 13:41:22
     *@create周润玉
    */
    const _initRequestDict = () => {
        //判断获取的用户 token 是否有值
        let defaultToken = JSON.parse(Utils.GetSessionStorage('SNUserInfo'));
        if (Utils.IsNotNull(defaultToken)) { //有值
            _initCommand();
        } else {
            $.ajax({
                url: Utils.CurDomain.WeiXinUrl + '/wxauths/code',
                type: 'GET',
                timeout: 3000,
                data: {
                    "code": Utils.GetQueryString('code'),
                    "state": Utils.GetQueryString('state'),
                    "type": Utils.GetQueryString('type')
                },
                success: function (res) {
                    if (res.isSucceed == true)
                        Utils.SetSessionStorage("SNUserInfo", res.data);/* 将用户信息openId/unionId缓存到Session中*/
                    _initCommand();
                },
                "error": Utils.AjaxError
            });
        }
    };

    /**
     *@file 命令初始化
     *@Date :2022-04-15 13:41:07
     *@create周润玉
    */
    const _initCommand = () => {
        //循环加载类别样式数据
        // requestDict(DictionaryType.FEEDBACK_TYPE).then(res => {

        // });
        $.ajax({
            url: "../../../../public/datas/ctn/feedbackconfig.json",
            type: "GET",
            dataType: "json",
            success: function (res) {
                if (res.isSucceed == true) {
                    res.data.forEach(element => {
                        let html =
                            '<div class="categoryContent" data-id="' + element.id + '" style="padding: 10px;">' +
                            '<div class="weui-cell weui-cell_select">' +
                            '<div style="margin: 0 auto;">' +
                            '<span style="font-size: 18px;">' + element.name + '</span>'
                        '</div>'
                        '</div>'
                        '</div>';
                        $('#main-category').append(html);
                    });
                }
            },
            error: function (e) {
                console.error(e);
            }
        });
        //点击分类标签获取名称
        $(document).on('click', '.categoryContent', function (e) {
            let textShow = $(this)[0].innerText;
            let id = $(this)[0].dataset.id;

            let appid = '';
            let wxState = Utils.GetQueryString('state');
            if (wxState == TEST_NUMBER.sourceID) {
                appid = TEST_NUMBER.id; //神农IT服务测试号
            } else if (wxState == TEST_INFO_NUMBER.sourceID) {
                appid = TEST_INFO_NUMBER.id; //神农信息服务测试号
            } else if (wxState == Collaboration_APP.sourceID) {
                appid = Collaboration_APP.id; //神农IT服务
            } else if (wxState == Service_APP.sourceID) {
                appid = Service_APP.id; //神农信息服务
            }

            location.href = '../feedback/feedback.html?category=' + textShow + '&id=' + id + '&appid=' + appid + '&state=' + wxState + '';
        });
    }


})(window, document, jQuery)